import { createRouter, createWebHashHistory } from 'vue-router';
import Layout from '@/components/layout.vue';// 引用layout组件

const routes = [// 配置路由规则
  { path: '/', redirect: '/main' },
  { path: '/login', name: 'login', component: () => import("@/view/login.vue") },
  {
    path: '/main', name: 'main', component: Layout, redirect: '/home', children: [
      { path: '/home', name: 'home', component: () => import("@/view/home/index.vue") },
    ]
  },
  {
    path: '/goods', name: '网站概况', component: Layout, children: [
      { path: 'goods-list', name: '商品列表', component: () => import("@/view/goods/index.vue") },
      { path: 'goods-info', name: '商品详情', component: () => import("@/view/goodsInfo/index.vue") },
    ]
  },
  {
    path: '/goods', name: '趋势分析', component: Layout, children: [
      { path: 'goods-list', name: '实时访客', component: () => import("@/view/goods/index.vue") },
      { path: 'goods-info', name: '今日统计', component: () => import("@/view/goodsInfo/index.vue") },
    ]
  },
  {
    path: '/user', name: "来源分析", component: Layout, children: [
      { path: 'user-list', name: '全部来源', component: () => import("@/view/user/index.vue") },
      { path: 'user-setting', name: '搜索引擎', component: () => import("@/view/user/userSetting.vue") },
      { path: 'user-list', name: '关键词', component: () => import("@/view/user/index.vue") },
      { path: 'user-setting', name: '外部链接', component: () => import("@/view/user/userSetting.vue") },
    ]
  },
  { path: "/:pathMathc(.*)*", name: "NotFound", component: () => import("@/view/notFound/index.vue") }
];

const router = createRouter({
  history: createWebHashHistory(),// hash模式
  routes
})
// router.beforeEach((to, from, next) => {// 路由守卫
//   if (to.path === '/login') return next();
//   const token = sessionStorage.getItem("token");
//   if (!token) return next("/login");// 判断是否有token
//   next();
// });

export default router;